package com.hsxxherp.ation.oauth2.center.server.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.hsxxherp.ation.oauth2.center.server.entity.UaaClient;
import com.hsxxherp.ation.oauth2.center.server.service.ISysTokenService;
import com.hsxxherp.ation.oauth2.center.server.service.IUaaClientService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


/**
 * TokenServivr实现类
 */
@Slf4j
@Service
public class SysTokenServiceImpl implements ISysTokenService {

    @Autowired
    private IUaaClientService uaaClientService;

    @Override
    public void preCheckClient(String clientId, String clientSecret) {
        if (clientId == null) {
            throw new RuntimeException("身份验证失败，缺少client_id参数");
        }
        if (clientSecret == null) {
            throw new RuntimeException("身份验证失败，缺少client_secret参数");
        }
    }

    @Override
    public boolean getClientTokenInfo(String clientId, String clientSecret) {
        this.preCheckClient(clientId, clientSecret);
        LambdaQueryWrapper<UaaClient> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(UaaClient::getClientId, clientId);
        UaaClient uaaClient = null;
        try {
            uaaClient = uaaClientService.getOne(queryWrapper);
        } catch (Exception e) {
            e.printStackTrace();
        }

        log.info("uaaClient:{}", uaaClient.toString());
        // 获取client信息
        return true;
    }
}
